﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             x:Class="Schedulr.Views.StatusPanel"
             d:DesignHeight="300"
             d:DesignWidth="300"
             mc:Ignorable="d" 
             DataContext="{Binding Path=StatusPanelViewModel, Source={StaticResource Locator}}">
    <Grid>
        <Grid.Style>
            <Style TargetType="Grid" BasedOn="{StaticResource {x:Type Grid}}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ExecutingTasks.Count}" Value="0">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Style>
        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" MaxHeight="100">
            <Border Margin="5" Padding="5" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1,0,0,0">
                <ItemsControl ItemsSource="{Binding ExecutingTasks}" VerticalAlignment="Center">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid Grid.Column="0" VerticalAlignment="Top">
                                    <Grid.Style>
                                        <Style TargetType="Grid" BasedOn="{StaticResource {x:Type Grid}}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Path=Task.IsComplete, Mode=OneWay}" Value="True">
                                                    <Setter Property="Visibility" Value="Collapsed" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Grid.Style>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <ProgressBar Grid.Column="0" Value="{Binding Path=Task.PercentComplete, Mode=OneWay}" Minimum="0" Maximum="1" Width="50" Height="10" Margin="0,0,5,0">
                                        <ProgressBar.Style>
                                            <Style TargetType="ProgressBar" BasedOn="{StaticResource {x:Type ProgressBar}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Path=Task.IsError, Mode=OneWay}" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource ErrorForegroundBrush}" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Path=Task.IsWarning, Mode=OneWay}" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource WarningForegroundBrush}" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Path=Task.PercentComplete, Mode=OneWay}" Value="{x:Null}">
                                                        <Setter Property="IsIndeterminate" Value="True" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ProgressBar.Style>
                                    </ProgressBar>
                                    <TextBlock Grid.Column="1" Text="{Binding Path=Task.PercentComplete, Mode=OneWay, StringFormat='{}{0:00%} | '}" Foreground="{DynamicResource UserMessageFontBrush}" FontSize="12" TextTrimming="CharacterEllipsis" />
                                </Grid>
                                <TextBlock Grid.Column="1" FontSize="12" VerticalAlignment="Top" TextTrimming="CharacterEllipsis">
                                    <Hyperlink Command="{Binding ShowDetailsCommand}" ToolTip="Click for details">
                                        <Hyperlink.Style>
                                            <Style TargetType="Hyperlink" BasedOn="{StaticResource {x:Type Hyperlink}}">
                                                <Setter Property="Foreground" Value="{DynamicResource UserMessageFontBrush}" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Path=Task.IsError, Mode=OneWay}" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource ErrorForegroundBrush}" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Path=Task.IsWarning, Mode=OneWay}" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource WarningForegroundBrush}" />
                                                    </DataTrigger>
                                                    <Trigger Property="IsEnabled" Value="False">
                                                        <Setter Property="TextDecorations" Value="None" />
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Hyperlink.Style>
                                        <TextBlock Text="{Binding Path=Task.Name}" TextTrimming="CharacterEllipsis" />
                                    </Hyperlink>
                                </TextBlock>
                                <TextBlock Grid.Column="2" Foreground="{DynamicResource UserMessageFontBrush}" FontSize="12" Text="{Binding Path=Task.Status, StringFormat=' : {0}', Converter={StaticResource singleLineConverter}}" VerticalAlignment="Top" TextTrimming="CharacterEllipsis" ToolTip="{Binding Path=Task.Status}">
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=Task.Status}" Value="{x:Null}">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                                </TextBlock>
                                <Popup Placement="Mouse" StaysOpen="False" IsOpen="{Binding DetailsVisible}">
                                    <Border Width="400" Height="200" Padding="2" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource DiagramGradientBrush}" BorderThickness="1">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>
                                            <Label Grid.Row="0" Content="{Binding Path=Task.Name, Mode=OneWay}" Padding="0" Style="{StaticResource SeparatingLabel}" />
                                            <TextBox Grid.Row="1" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Text="{Binding Path=StatusHistoryDescription, Mode=OneWay}" TextChanged="statusHistoryTextBox_TextChanged" />
                                            <Thumb Grid.Row="2" Cursor="SizeNWSE" HorizontalAlignment="Right" DragDelta="OnPopupDragDelta" Style="{DynamicResource ResizeGripThumbStyle}" />
                                        </Grid>
                                    </Border>
                                </Popup>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Border>
        </ScrollViewer>
    </Grid>

</UserControl>